package com.sugar.real.estate.module.business.dal.mysql.infohouse;

import com.sugar.real.estate.framework.common.pojo.PageResult;
import com.sugar.real.estate.framework.mybatis.core.mapper.BaseMapperX;
import com.sugar.real.estate.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.sugar.real.estate.module.business.controller.app.info.vo.AppInfoPageReqVO;
import com.sugar.real.estate.module.business.controller.app.info.vo.AppInfoRespVO;
import com.sugar.real.estate.module.business.dal.dataobject.info.InfoDO;
import com.sugar.real.estate.module.business.dal.dataobject.infohouse.InfoHouseDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 资讯与房屋关联信息 Mapper
 *
 * @author Ysugar
 */
@Mapper
public interface InfoHouseMapper extends BaseMapperX<InfoHouseDO> {

    @Select("select * " +
            "from business_info bi " +
            "where bi.deleted = 0" +
            " and bi.id =" +
            "  (select bih.info_id " +
            "   from business_info_house bih " +
            "   where bih.deleted = 0 and bih.`type` = #{param2} and bih.house_id = #{param1} " +
            "   order by id desc " +
            "   limit 1)")
    AppInfoRespVO selectListCustom(Long houseId, int type);

    default PageResult<AppInfoRespVO> selectPageByHouseId(AppInfoPageReqVO reqVO){
        return selectJoinPage(reqVO, AppInfoRespVO.class, new MPJLambdaWrapperX<InfoHouseDO>()
                .selectAll(InfoDO.class)
                .leftJoin(InfoDO.class, InfoDO::getId, InfoHouseDO::getInfoId)
                .eq(InfoHouseDO::getHouseId, reqVO.getHouseId())
                .eq(InfoHouseDO::getType, reqVO.getType()));
    }
}